home *** CD-ROM | disk | FTP | other *** search
- Path: cs.tu-berlin.de!news
- From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
- Newsgroups: comp.lang.c++
- Subject: Re: problem with bc++ (2) answers please
- Date: 29 Feb 1996 22:10:56 GMT
- Organization: Technical University of Berlin, Germany
- Message-ID: <4h589g$5hf@news.cs.tu-berlin.de>
- NNTP-Posting-Host: 130.149.17.230
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
-
- aragonne@mail.planete.net (ragonnet alain) writes:
- > /*********************************************************************
- > * PROGAMME AVEC BC++ VERSION 4.52
- > *********************************************************************/
- >
- > #include<stdio.h>
- >
- > main( void)
- > {
- > int tab[]= { 0, 1, 2}, *ptr= tab;
- >
- > printf("\n ref: %d , pointeur: %d\n", ptr, *ptr);
- > /*instruction qui ne fonctionne pas avec BC++ */ (this instrucion is not ok with BC++)
- > printf("\n ref: %d", ptr);
- > printf("\n pointeur: %d", *ptr);
- > /*Ces 2 instructions fonctionnent correctement */(this two instructions are ok )
- > }
- > /*
- >
- > ref: 3672 , pointeur: 0
- >
- > ref: 3672
- > pointeur: 0
- > Peut-on me dire d'ou vient le probleme.Ce programme fonctionne
- > correctement avec QC 2.5 par exemple*/
- >
- > Can you tell me where is the problem please.This program is working well
- > with QC 2.5 for exemple*/
- >
- > thank you for answers
- >
-
- I'm not sure what's the matter with my server; I think my response didn't
- make it, so once again...
-
- Generally, you can't use "%d" to printf a pointer value. "%d" is used to
- print an integer and a pointer is not guaranteed to have the same size
- as the integer. On MSDOS machines the pointer size depends on the memory
- model. If using the SMALL model everything is fine since both integers and
- pointers are two bytes. In the large model, however, a pointer is four
- bytes. Thus, a call like printf( "%d %d", ptr, *ptr ) would first print
- the lower word of the pointer value and then the higher word. Just correct
- the first "%d" to "%p" or "%lp" and it will work.
-
- Bye
-
- Roman
-
-